/*
 * @描述: input配置信息遍历器
 * @Author: /songzi
 * @Date: 2019-07-19 18:29:55
 * @Last Modified by: songzi
 * @Last Modified time: 2020-03-18 14:34:33
 */
import React, { Fragment } from 'react';
import { Form } from 'antd';
import RenderInputType from './renderInputType';

const FormItem = Form.Item;

const RevInput = (render, decorator, getFieldDecorator, inputItem) => {
  if (render) return render;
  const { decoratorConfig = {}, initialValue } = inputItem;
  if (!decorator) return RenderInputType(inputItem);
  return getFieldDecorator(inputItem.name, {
    initialValue,
    ...decoratorConfig
  })(RenderInputType(inputItem));
};

const MapInput = ({ getFieldDecorator, inputConfig }) => {
  const InputList = inputConfig.map(inputItem => {
    const { label = '', name, render, decorator, isHide, formItemProp = {} } = inputItem;
    return (
      <FormItem key={name} label={label} {...formItemProp} style={{ display: !isHide ? 'block' : 'none' }}>
        {RevInput(render, decorator, getFieldDecorator, inputItem)}
      </FormItem>
    );
  });
  return InputList;
};
export default MapInput;
